#include<conio.h>
#include<stdio.h>
long arr[1000000];
long n,i;
/***************** Heapsoft ******************/
void adjust(long root,long endnode){
    long c,key=arr[root];
    while(root*2<=endnode){
        c=root*2;
        if(c<endnode && arr[c]<arr[c+1])c++;
        if(arr[c]<=key)break;
        arr[root]=arr[c];root=c;
    }
    arr[root]=key;
}
void heapsort(){
    long temp;
    for(long r=n/2;r>=1;r--)adjust(r,n);
    for(long i=n;i>=2;i--){
        temp=arr[1];
        arr[1]=arr[i];
        arr[i]=temp;
        adjust(1,i-1);
    }
}
/*******************End heapsort ************/
int main(){
    FILE *fp=fopen("HEAP.INP","r");
    fscanf(fp,"%ld",&n);
    for(i=1;i<=n;i++)fscanf(fp,"%ld",&arr[i]);
    fclose(fp);
    heapsort();
    fp=fopen("HEAP.OUT","w");
    for(i=1;i<=n;i++)fprintf(fp,"%ld\n",arr[i]);
    fclose(fp);
    return 0;
}
    
        
